// pages/reviewDetails/index.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isTrue:false,
    ambientFraction: 0,
    priceFraction:0,
    serviceFraction:0,
    comment:'',
    isNoName:0,
    object:{}
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    var eventChannel = that.getOpenerEventChannel()
    eventChannel.on('reviewDetails', function (data) {
      that.setData({
        object:data.item
      })
    })
    console.log(this.data.object)
  },
  selectTrue(){
    if(this.data.isTrue){
      this.setData({
        isTrue:false
      })
    }else{
      this.setData({
        isTrue:true
      })
    }
  },
  onChange(event) {
    this.setData({
      value: event.detail,
    });
  },
  gotonav(){
    wx.navigateBack({
      delta: 1
    })
  },
  submit(){
    wx.showLoading({
      title: '提交中',
      mask:true
    })
    let data = {
      ambientFraction:this.data.ambientFraction,
      comment:this.data.comment,
      priceFraction:this.data.priceFraction,
      serviceFraction:this.data.serviceFraction,
      userId:wx.getStorageSync('userLogin').userId,
      orderId:this.data.object.id,
      isNoName:this.data.isNoName
    }
    app.agriknow.userComment(data).then(res=>{
      console.log(res)
      wx.hideLoading()
      if(res.code=='000000'){
        this.tipsMessage('提交成功')
        setTimeout(() => {
          wx.navigateBack({
            delta: 1
          })
        }, 1500);
      }
    }).catch(res=>{
      wx.hideLoading()
      wx.showToast({
        title: res.message,
        icon: 'none',
        duration: 2000,
        mask: true
      })
    })
  },
  isYes(){
    this.setData({
      isNoName:1
    })
  },
  isNo(){
    this.setData({
      isNoName:0
    })
  },
  ambientFractionChange(event) {
    this.setData({
      ambientFraction: event.detail,
    });
  },
  priceFractionChange(event) {
    this.setData({
      priceFraction: event.detail,
    });
  },
  serviceFractionChange(event) {
    this.setData({
      serviceFraction: event.detail,
    });
  },
  //提示信息
  tipsMessage(text) {
    wx.showToast({
      title: text,
      icon: 'none',
      duration: 2000,
      mask: true
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})